<template>
	<view>

	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		created() {
			const price = parseFloat(this.getUrlKey('price')).toFixed(2)
			const goodName = this.getUrlKey('goodName')
			const token = this.getUrlKey('token')
			let payWay = '';
			var browser = navigator.userAgent.toLowerCase();
			if (browser.match(/Alipay/i) == "alipay") {
				payWay = 'alipay'
			} else if (browser.match(/MicroMessenger/i) == "micromessenger") {
				payWay = 'wechat'
			} else {
				alert('请用微信或支付宝扫描二维码')
				return
			}
			this.pay(price, goodName, payWay, token);
		},
		methods: {
			pay(price, goodName, payWay, token) {
				// 初始化,模式：测试test，正式prod
				Jnpay.init("prod");
				// var r = confirm("是否发起支付")
				// if (r == true) {
					// 执行支付
					Jnpay.doPay({
						// 店铺ID：长整型
						// storeId: 1576562293774760, //测试
						storeId: 1583119219481033, // 正式
						// 支付金额，小数2位
						price: price,
						// 商品名称
						goodName: goodName,
						// 支付成功的异步回调地址
						serverUrl: "http://tv.kdtyun.com/ad1/public/index.php?s=api/pay/getPayResult/token/" + token + '/type/2',
						// 支付方式，仅支持：微信wechat，支付宝alipay
						payMode: payWay,
						// 支付成功后页面重定向路径
						successPageUrl: "https://ffcy.stqcm.com/lunch/#/pages/android-pay/pay-status?status=1",
						// 支付失败后页面重定向路径
						errorPageUrl: "https://ffcy.stqcm.com/lunch/#/pages/android-pay/pay-status?status=2"
					});
				// }
				var hasShare = true;
				/* begin禁用微信分享功能 */
				function funonBridgeReady() {
					WeixinJSBridge.call('hideOptionMenu');
				}
				if (!hasShare) {
					if (typeof WeixinJSBridge == "undefined") {
						if (document.addEventListener) {
							document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
						} else if (document.attachEvent) {
							document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
							document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
						}
					} else {
						onBridgeReady();
					}
				}
				/* end禁用微信分享功能 */
			},
		}
	}
</script>

<style>

</style>
